﻿using MainInterface;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace MainProGrid
{
    /// <summary>
    /// 自定义对象选择类
    /// </summary>
    public class CustomSelectObject : ICustomTypeDescriptor, ISelectObj
    {
        /// <summary>
        /// 属性
        /// </summary>
        public List<CustomProperty> Properties = new List<CustomProperty>();
        /// <summary>
        /// 事件
        /// </summary>
        public List<CustomEvent> Events = new List<CustomEvent>();


        #region ICustomTypeDescriptor 成员
        public AttributeCollection GetAttributes()
        {
            return TypeDescriptor.GetAttributes(this, true);
        }
        public string GetClassName()
        {
            return TypeDescriptor.GetClassName(this, true);
        }
        public string GetComponentName()
        {
            return TypeDescriptor.GetComponentName(this, true);
        }
        public TypeConverter GetConverter()
        {
            return TypeDescriptor.GetConverter(this, true);
        }
        public EventDescriptor GetDefaultEvent()
        {
            return TypeDescriptor.GetDefaultEvent(this, true);
        }
        public PropertyDescriptor GetDefaultProperty()
        {
            return TypeDescriptor.GetDefaultProperty(this, true);
        }
        public object GetEditor(Type editorBaseType)
        {
            return TypeDescriptor.GetEditor(this, editorBaseType, true);
        }
        public EventDescriptorCollection GetEvents(Attribute[] attributes)
        {
            return TypeDescriptor.GetEvents(this, attributes, true);
        }
        public EventDescriptorCollection GetEvents()
        {
            return TypeDescriptor.GetEvents(this, true);
        }
        public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            PropertyDescriptor[] newProps = new PropertyDescriptor[this.Properties.Count];
            for (int i = 0; i < this.Properties.Count; i++)
            {
                CustomProperty prop = (CustomProperty)this.Properties[i];
                newProps[i] = new CustomPropertyDescriptor(ref prop, attributes);
            }
            
            return new PropertyDescriptorCollection(newProps);
        }
        public PropertyDescriptorCollection GetProperties()
        {
            return TypeDescriptor.GetProperties(this, true);
        }
        public object GetPropertyOwner(PropertyDescriptor pd)
        {
            return this;
        }
        #endregion
        /// <summary>
        /// 返回事件属性
        /// </summary>
        /// <returns></returns>
        public PropertyDescriptorCollection GetEventProperties(Attribute[] attributes)
        {
            PropertyDescriptor[] newProps = new PropertyDescriptor[this.Events.Count];
            for (int i = 0; i < this.Events.Count; i++)
            {
                CustomEvent prop = (CustomEvent)this.Events[i];
                newProps[i] = new CustomEventDescriptor(ref prop, attributes);
            }
            return new PropertyDescriptorCollection(newProps);
        }
    }  
}
